import React, { useEffect, useState } from "react";
import { useLocation, useNavigate } from "react-router-dom";
import "../../../styles/Allocate/List/Edit.scss"
import { Form, Button, Input, message } from "antd";
import { Edit_list } from "../../../utils/api"
interface Props { }
function Edit(props: Props) {
    var location = useLocation();
    var navigate = useNavigate();
    var [data, setData] = useState([]);
    useEffect(() => {
        setData(location.state);
    });
    console.log(data);

    const [form] = Form.useForm();
    useEffect(() => {
        form.setFieldsValue({
            id: location.state.id,
            key: location.state.key,
            tracking: location.state.tracking,
            people: location.state.people,
            diaochu: location.state.diaochu,
            shenqing: location.state.shenqing,
            shenhetime: location.state.shenhetime,
            outbound: location.state.outbound,
            ruku: location.state.ruku,
            shenhe: location.state.shenhe,
        })
    }, [data]);
    const onFinish = (values: any) => {
        //编辑
        Edit_list(values).then((res) => {
            console.log(res.data);
            if (res.request.status == 200) {
                message.open({ type: "success", content: "编辑成功!" });
                navigate("/index/home/AllocateManagement");
            } else {
                message.open({ type: "error", content: "编辑失败!" });
            }
        });
    };
    const onFinishFailed = (errorInfo: any) => {
        console.log("Failed:", errorInfo);
    };
    let cancel = function () {
        navigate("/index/home/AllocateManagement");
    };
    return (
        <div className='Edit'>
            <div className='top'>仓储管理 / 出库管理 / 编辑出库</div>
            <div className="table">
                <Form
                    form={form}
                    name="basic"
                    labelCol={{ span: 6 }}
                    wrapperCol={{ span: 22 }}
                    initialValues={{ remember: true }}
                    onFinish={onFinish}
                    onFinishFailed={onFinishFailed}
                    autoComplete="off"
                >
                    <Form.Item label="ID号" name="id" hidden>
                        <Input />
                    </Form.Item>
                    <Form.Item label="调拨单号" name="tracking">
                        <Input />
                    </Form.Item>
                    <Form.Item label="操作人员" name="people">
                        <Input />
                    </Form.Item>
                    <Form.Item label="调出仓库" name="diaochu">
                        <Input />
                    </Form.Item>
                    <Form.Item label="申请时间" name="shenqing">
                        <Input />
                    </Form.Item>
                    <Form.Item label="审核时间" name="shenhetime">
                        <Input />
                    </Form.Item>
                    <Form.Item label="出库时间" name="outbound">
                        <Input />
                    </Form.Item>
                    <Form.Item label="入库时间" name="ruku">
                        <Input />
                    </Form.Item>
                    <Form.Item label="审核状态" name="shenhe">
                        <Input />
                    </Form.Item>
                    <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
                        <Button className="btn" onClick={cancel}>
                            取消
                        </Button>
                        <Button className="btn" type="primary" htmlType="submit">
                            保存
                        </Button>
                    </Form.Item>
                </Form>
            </div>
        </div>
    );
}

export default Edit;